home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 7142 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.6 KB  |  101 lines

  1. Path: god.bel.alcatel.be!nlev00!barnhoorn
  2. From: barnhoorn@nlev00 ()
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: Messages vs. Semaphores for external clocking
  5. Date: 10 Apr 1996 10:34:02 GMT
  6. Organization: Alcatel Bell
  7. Distribution: world
  8. Message-ID: <4kg2qq$58l@btmpjg.god.bel.alcatel.be>
  9. References: <4ju349$r1e@sparky.navsea.navy.mil> <4jvrqs$hk0@btmpjg.god.bel.alcatel.be> <heinz.17rm@hwg.muc.de> <4kfmes$lle@btmpjg.god.bel.alcatel.be> <4kfuhb$ahh@serpens.rhein.de>
  10. Reply-To: barnhoorn@nlev00 ()
  11. NNTP-Posting-Host: 138.203.178.61
  12. X-Newsreader: mxrn 6.18-10
  13.  
  14.  
  15. In article <4kfuhb$ahh@serpens.rhein.de>, mlelstv@serpens.rhein.de (Michael van Elst) writes:
  16. >barnhoorn@nlev00 () writes:
  17. >
  18. >>.not so obviously. When you have two tasks, and one of them is
  19. >>collecting data from some source, and the other one needs this data
  20. >>with regular intervals, I don't see a more easier way to do this
  21. >>then by using global data and disable/enable multitasking.
  22. >
  23. >The trick is to disable multitasking only when necessary and only
  24. >for the tasks that are involved.
  25. >
  26. >>It is
  27. >>a very multitasking-friendly solution,
  28. >
  29. >No. You stop all other tasks (and with Disable() you even stop
  30. >interrupts which is nonsense). 
  31.  
  32. Agree (I meant Forbid()/Permit()). But 'you stop all other tasks'
  33. is wrong. In my Amiga only ONE task is running at the same time.
  34. When task 1 wants the data, the only thing it has to do is disable
  35. multitasking, (which does NOT stop all other tasks because they are
  36. already stopped), collect the data, and enable the multitasking again.
  37. We are talking (well, at least I am) here about very SIMPLE code
  38. like this:
  39.  
  40.  
  41. int global_data;
  42. int running;
  43.  
  44. void Task1 (void)
  45. {
  46.     int local_data;
  47.  
  48.     while (running) {
  49.  
  50.         Forbid();
  51.         local_data=global_data;
  52.         Permit();
  53.  
  54.         HandleDataFromOtherTask(local_data);
  55.  
  56.         WaitRegularInterval();
  57.     }
  58. }
  59.  
  60. void Task2(void)
  61. {
  62.     int local_data;
  63.  
  64.     while (running) {
  65.  
  66.         CollectDataForMainTask(&local_data);
  67.  
  68.         Forbid();
  69.         global_data=local_data;
  70.         Permit();
  71.  
  72.         WaitRegularInterval();
  73.     }
  74. }
  75.  
  76. void main(void)
  77. {
  78.     running=1;
  79.  
  80.     /* start the two processes */
  81.  
  82.     /* do whatever you like, you may even Wait() for user-interrupt */
  83.  
  84.     running=0;
  85.  
  86.     /* wait for the two processes to finish */
  87. }
  88.  
  89.  
  90. I really only wanted to state that in my opinion, forbid() and permit()
  91. is the most easiest, shortest and probably also fastest way to transfer
  92. the data from task2 to task1.
  93.  
  94. -- 
  95. ---------------------------------------------------------------------------
  96. Jaco Barnhoorn               barnie@xs4all.nl
  97. Software Test Engineer       barnhoorn%nlev00@btmv56.se.bel.alcatel.be
  98. Alcatel Telecom Systems
  99. Rijswijk, The Netherlands
  100. ---------------------------------------------------------------------------
  101.